package huoye.shops.huoye.operation.presenter;

import com.codeideology.android.lang.entity.Paging;

import java.util.List;

import huoye.shops.base.BasePresenter;
import huoye.shops.base.MineBaseJsonRequestCallback;
import huoye.shops.huoye.mine.model.ProductInfo;
import huoye.shops.huoye.operation.model.ShopPrizeList;
import huoye.shops.huoye.operation.model.ShopProductList;
import huoye.shops.huoye.operation.networt.OperationService;
import huoye.shops.huoye.operation.view.IManagePrizeRefreshView;
import huoye.shops.huoye.operation.view.IManageProductRefreshView;


/**
 * Created by uesr on 2017/7/19.
 */

public class ManageProductPresenter extends BasePresenter<IManageProductRefreshView> {

    OperationService mService;

    //获取商家商品列表
    public void getProductList(String seek,int productType,final Paging paging){
        mService.getProductList(seek,productType,paging, new MineBaseJsonRequestCallback<ShopProductList>(ShopProductList.class) {

            @Override
            public void onSuccess(List<ShopProductList> list) {
                super.onSuccess(list);
                view.setDataSet(list,paging);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }


    //商家获取商品信息
    public void getProductInfo(String productId){
        mService.getProductInfo(productId, new MineBaseJsonRequestCallback<ProductInfo>(ProductInfo.class) {


            @Override
            public void onSuccess(ProductInfo productInfo) {
                super.onSuccess(productInfo);
                view.getProductInfoData(productInfo);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });

    }




    @Override
    public void onStart() {
        mService = new OperationService();
    }
}
